﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClientOverflow.DataTransferObjects;

namespace ClientOverflow.ViewModels.KnowledgeSummaryViewModels
{
    public class KnowledgeSummaryViewModel
    {
        public  IEnumerable<TagActivityViewModel> TagsActivities { get; private set; }

        public KnowledgeSummaryViewModel()
        {
            Question[] questions;
            Tag[] tags;
            using (var serviceClient = ServicesFactory.CreateClientOverflowServiceClient())
            {
                questions = serviceClient.GetAllQuestions();
                tags = serviceClient.GetAllTags();
            }

            var tagsQuestions = tags
                .GroupBy(tag => tag, tag => questions.Where(question => question.Tags.Contains(tag)));

            TagsActivities = tagsQuestions.Select(tagGroup => new TagActivityViewModel(tagGroup.Key, tagGroup));
        }
    }
}
